<template>
    <div>
        <scale-loader :loading="loading" :color="color"></scale-loader>
    </div>
</template>
<script>
import { mapMutations } from 'vuex'
import ScaleLoader from 'vue-spinner/src/ScaleLoader.vue'
import API from '@/service/api'
export default {
    components: {
        ScaleLoader
    },
    data() {
        return {
            loading: true,
            color: '#2772ff'
        }
    },
    methods: {
        ...mapMutations([
            'RECORD_LOGIN_USER',
            'RECORD_TOKEN',
            'RECORD_SAMPLE_ID',
            'RECORD_SAMPLE_NO',
            'RECORD_BAND_NO',
            'RECORD_BAND_ID',
            'UPDATE_SHOW_LOADING',
        ]),
        async initialization() {
            this.UPDATE_SHOW_LOADING(false)
            let res = await API.wxLogin({code: this.$route.query.code})
            this.RECORD_LOGIN_USER(res.accountInfo)
            this.RECORD_TOKEN(res.token)
            let page = this.$route.query.page
            const id = this.$route.query.id
            const no = this.$route.query.guid
            let params = {}
            if(page == 'bandDetail') {
                if(no) this.RECORD_BAND_NO(no)
                if(id) this.RECORD_BAND_ID(id)
            }else if(page == 'confirmDetail') {
                page = 'confirmList'
                params =  { suppliers: id }
            }else if(page == 'auditionDetail' || page == 'resolveDetail') {
                page = page.split('Detail')[0]
            }
            if(no) this.RECORD_SAMPLE_NO(no)
            if(id) this.RECORD_SAMPLE_ID(id)
            this.$router.push( { path: `/${page}`, params } )
        }
    },
    created() {
       this.initialization()
    } 
}
</script>
<style scoped>
.v-spinner{
    width: 50px;
    height: 20px;
    margin: auto;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}
</style>

